<?php
if($_POST)
{
	if(!$_POST['mode'] || !$_POST['contect'] || !$_POST['form'])
	{
		header("Content-type: text/html; charset=utf-8");
		die('ERRO:无提交数据！');
	}

	$pattern = preg_replace(array('/_0_/','/_1_/'),array('(?:\s?[^\s]*\s?)','([^"]+)'),str_replace('/','\/',$_POST['mode']));	
	$contect = doString($_POST['contect']); 
	$contect = strip_tags($contect, '<a>,<img>');

	preg_match_all("/$pattern/",$contect, $out, PREG_PATTERN_ORDER);
	
	$num = count($out);
	if(!$out[0])
	{
		die('ERRO:没有匹配到数据！');
	}

	foreach($out[0] as $key => $val)
	{
		for($i = 1;$i < $num;$i++)
		{
			$hz = end(explode('.',basename($out[$i][$key])));
			if(in_array($hz, array('jpg','gif','png')))
			{
				$data[$key]['img'] = $out[$i][$key];
			}
			elseif(in_array($hz, array('shtml','html','php','htm')) || substr($out[$i][$key], 0, 6)=="/html/")
			{
				$data[$key]['link'] = $out[$i][$key];
			}else{
				$data[$key]['name'] = $out[$i][$key];
			}
		}
	}
	foreach($data as $val)
	{
		$_->source->_insert(array('name'=>$val['name'],'link'=>$val['link'],'img'=>$val['img'],'imgfile'=>$val['imgfile'],'step'=>1));
	}
}	
	$data = $_->source->_select('*',array('step'=>3));
	
	$from = $_POST['form']?$_POST['form']:$_GET['form'];
	$from = $from?$from:1;
	$smarty->_assign(array('data','from'));
	$smarty->_display();

	function doString($string)
	{
		$string = str_replace(array(PHP_EOL,'\"'), array('','"'),$string);
		return preg_replace('/>\s+</', '><', $string);
	}
?>